package com.shaozj.auth.service;

import cn.hutool.extra.spring.SpringUtil;
import com.shaozj.core.exception.BizException;
import com.shaozj.auth.model.form.PasswordLoginForm;

/**
 * 授权策略
 */
public interface IAuthStrategy {

    String BEAN_NAME = "AuthStrategy";

    /**
     * 登录
     * @param body
     * @param grantType 授权类型
     * @return
     */
    static void login(PasswordLoginForm body, String grantType) {
        String beanName = grantType + BEAN_NAME;
        if (!SpringUtil.getBeanFactory().containsBean(beanName)) {
            throw new BizException("授权类型不正确!");
        }
        IAuthStrategy authStrategy = SpringUtil.getBean(beanName, IAuthStrategy.class);
        authStrategy.login(body);
    }

    /**
     * 登录
     * @param body
     * @return
     */
    void login(PasswordLoginForm body);

}
